package com.ethan.orika;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ma.glasnost.orika.CustomConverter;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.ConverterFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.Type;
import qunar.api.pojo.Money;

/**
 * @author ethan
 * create 2018-06-06 上午9:54
 * desc
 **/
public class OrikaTest8 {
    public static void main(String[] args){

        PersonModel personModel = new PersonModel(1,"zs",20.0,25,10);

        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        ConverterFactory converterFactory = mapperFactory.getConverterFactory();
        converterFactory.registerConverter(new MyConvertter());

        mapperFactory.classMap(PersonModel.class,PersonDB.class).byDefault().register();

        PersonDB personDB = mapperFactory.getMapperFacade().map(personModel,PersonDB.class);

        String a="";
    }

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    public static class PersonModel{
        private Integer id;
        private String name;
        private Double price;
        private Integer age;
        private Integer gender;
    }


    public static class PersonDB{
        private int id;
        private String name;
        private double price;
        private int age;
        private int gender;
    }

    public static class MyConvertter extends CustomConverter<Integer,Integer> {
        @Override
        public Integer convert(Integer source, Type<? extends Integer> destinationType, MappingContext mappingContext) {
            return source;
        }
    }

}
